Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-8623] - Introduce TanStack Router #10997

Merged
merged 45 commits into from
Oct 4, 2024

Conversation

abailly-akamai
Copy link
Contributor

@abailly-akamai abailly-akamai commented Sep 24, 2024

Screenshot 2024-10-03 at 11 45 08

Description 📝

This (large) PR introduces TanStack Router to Cloud Manager.

https://tanstack.com/router/latest

It prepares a full migration from our old, outdated v5 react-router-dom to the new Routing API.

The benefits of this migration are multiple:

  • very low dependency
  • 100% inferred TypeScript support
  • Typesafe navigation
  • Nested Routing and layout routes
  • Built-in Route Loaders w/ SWR Caching
  • Designed for client-side data caches (TanStack Query, SWR, etc.)
  • Automatic route prefetching
  • Asynchronous route elements and error boundaries
  • File-based Route Generation
  • Typesafe JSON-first Search Params state management APIs
  • Path and Search Parameter Schema Validation
  • Search Param Navigation APIs
  • Custom Search Param parser/serializer support
  • Search param middleware
  • Route matching/loading middleware

Important

This initial PR does not (read should not) affect the current Cloud Manager routing experience. It only aims to achieve the following:

  • consistent file splitting/lazy loading
  • centralized routes (parity with existing routes

I do not expect to have 100% route parity with this PR, I however did my very best get as close as possible. Subsequent PRs will rollout the actual new routing by updating legacy utils with the TanStack ones (params, location, history, etc)

Changes 🔄

  • Create lazy exports for routed components
  • Create all existing routes in centralized location
  • Configure root and routing architecture

How to test 🧪

Prerequisites

  • pull code locally and run yarn to get new dependency

Verification steps

  • Confirm this PR does not introduce any functional change or regression
  • Switch the routing in <App /> to very basic functionality
    • important because we only defined the routes and have not replaced the utils, the experience may be very buggy for many routes - using MSW legacy handlers will help a bit with that matter

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

maxWidth: '100%',
position: 'relative',
},
}));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing styles from <MainContent /> extracted to their own file - this also isn't affecting the current experience

</SessionExpirationProvider>
</div>
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decoupled the root from the so the saparation of concern between routing and composition is more clear. This is not affecting the current experience (unless switching things in <App /> manually)

});

return <RouterProvider router={router} />;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our new entrypoint to load all routes in Cloud Manager (not active in this PR!)

'/account-activation'
)({
component: AccountActivationLanding,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All createLazyRoute exports you will see in this PR aim to facilitate lazy loading smaller bundles: https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction#createlazyroute-function

Those get imported in the /routes/* files via .lazy()

@abailly-akamai abailly-akamai marked this pull request as ready for review October 3, 2024 15:54
@abailly-akamai abailly-akamai requested a review from a team as a code owner October 3, 2024 15:54
@abailly-akamai abailly-akamai requested review from mjac0bs, bnussman-akamai and jaalah-akamai and removed request for a team October 3, 2024 15:54
Copy link

github-actions bot commented Oct 3, 2024

Coverage Report:
Base Coverage: 87.19%
Current Coverage: 87.24%

sx={{ paddingLeft: theme.spacing(1) }}
variant="h2"
>
Invoice #{invoice.id}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the removal of the # is causing an e2e test failure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes thank you, this change is unrelated but we did not have any h1 on this page so i thought to add one (was helpful during my testing to have an H1 on each page for assertions that the page is rendering something within the route. I'll fix it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@jaalah-akamai jaalah-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is amazing work 🔥 - I still want to look deeper into this, but here's some minor stuff I found.

packages/manager/src/routes/utils/allPaths.ts Outdated Show resolved Hide resolved
packages/manager/src/routes/utils/allPaths.ts Outdated Show resolved Hide resolved
packages/manager/src/routes/profile.tsx Outdated Show resolved Hide resolved
packages/manager/src/routes/stackscripts.tsx Outdated Show resolved Hide resolved
packages/manager/src/routes/support.tsx Outdated Show resolved Hide resolved
packages/manager/src/routes/index.tsx Show resolved Hide resolved
Copy link
Member

@bnussman-akamai bnussman-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall structure and patterns look good to me!

@abailly-akamai abailly-akamai merged commit ccb4e0b into linode:develop Oct 4, 2024
19 of 20 checks passed
Copy link

cypress bot commented Oct 4, 2024

Cloud Manager E2E    Run #6623

Run Properties:  status check passed Passed #6623  •  git commit ccb4e0bd9a: refactor: [M3-8623] - Introduce TanStack Router (#10997)
Project Cloud Manager E2E
Branch Review develop
Run status status check passed Passed #6623
Run duration 26m 06s
Commit git commit ccb4e0bd9a: refactor: [M3-8623] - Introduce TanStack Router (#10997)
Committer Alban Bailly
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 2
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 414
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants